package send;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class TestGlass extends JFrame {

	ProgressGlassPane glassPane = new ProgressGlassPane();
	public TestGlass() {
		JTable table = new JTable();
		table.setModel(new DefaultTableModel(
				new Object[][] {
						{ "aerith.png", "/www/progx/images/", "PNG", "5/17/2006" },
						{ "blog.html", "/www/progx", "HTML", "3/1/2006" },
						{ "index.html", "/www/progx", "HTML", "9/12/2006" }, 
						{ "pictures.zip", "/www/progx", "ZIP", "10/8/2006" } }, 
				new String[] { "Name", "Path", "Type", "Date" }));
		this.setLayout(new BorderLayout());
		this.setGlassPane(glassPane);
		Container container = this.getContentPane();
		container.setLayout(new BorderLayout());
		container.add(new JScrollPane(table));
		JButton button = new JButton("Run");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getGlassPane().setVisible(true);
				Thread downloader = new Thread(new Runnable() {
					public void run() {
						int i = 0;
						do {
							try {
								Thread.sleep(30 + (int) (Math.random() * 300));
							} catch (InterruptedException ex) {
							}
							i += (int) (Math.random() * 5);
							glassPane.setProgress(i);
						} while (i < 100);
						glassPane.setVisible(false);
						glassPane.setProgress(0);
					}
				});
				downloader.start();
			}
		});
		this.add(button,BorderLayout.SOUTH);
	}

	public static void main(String[] args) {
		TestGlass test = new TestGlass();
		test.setSize(500, 400);
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		test.setLocationRelativeTo(null);
		test.setVisible(true);
	}
}
